package com.dwd.basic.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @Description: TODO
 * @Author 汶狄
 * @Date 2020/12/14 21:35
 * @Version 1.0
 */
@Configuration  //等同于加了@Component
@EnableSwagger2//开启swagger2（swagger是老版，2是新版）
public class SwaggerConfig {
    //配置了swagger的bean实例,通过Docket对象接管了原来的默认配置。Docket这个对象有很多配置，现在就配了一个apiInfo参数
    @Bean //配置docket以配置Swagger具体参数
    public Docket docket(Environment environment) {

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("汶狄")
                //enable是否启动Swagger，如果为False，则Swagger不能再浏览器中访问
                .enable(true)
                .select()
                //配置要扫描接口的方式
                .apis(RequestHandlerSelectors.basePackage("com.dwd"))
                .build();//工厂模式
    }




    private ApiInfo apiInfo() {
        //作者信息
        Contact contact = new Contact("汶狄", "https://blog.csdn.net/duanwendi?spm=1001.2101.3001.5113", "1097466381@qq.com");
        return new ApiInfo(
                "汶狄的swaggerAPI文档",
                "即使再小的帆才能远航",
                "1.0",
                "https://blog.csdn.net/duanwendi?spm=1001.2101.3001.5113",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<VendorExtension>());
    }
}
